home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tex / tools / dvi / vdi_90.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  3.1 KB  |  145 lines

  1. /***************************************************************************/
  2. /*  Querdruck für GDOS-Drucker                                             */
  3. /***************************************************************************/
  4.  
  5.  
  6. #include <portab.h>
  7. #include <vdi.h>
  8. #include <string.h>
  9.  
  10. #include "mintbind.h"
  11. #include "treiber.h"
  12.  
  13.  
  14.  
  15. /* Versucht Zeile zu Komprimieren */
  16. LONG    compress_img_run( UBYTE *ziel, UBYTE *p, LONG *limit )
  17. {
  18.     UBYTE    i;
  19.  
  20.         /* Sonst getrennt */
  21.     if(  p[0]==0xFF  ||  p[0]==0  )
  22.     {
  23.         for(  i=1;  p[i]==p[0]  &&  i<*limit  &&  i<0x7F;  i++  )
  24.             ;
  25.         ziel[0] = (0x80 & p[0]) | i;
  26.         (*limit) -= i;
  27.         return 1;
  28.     }
  29.     else
  30.     {
  31.         /* Abstand zum nächsten Ungleichen... */
  32.         for(  i=0;  p[i]!=0  &&  p[i]!=0xFF  &&  i<127  &&  i<*limit;  i++  )
  33.             ziel[i+2] = p[i];
  34.         ziel[0] = 0x80;
  35.         ziel[1] = i;
  36.         (*limit) -= i;
  37.         return i+2;
  38.     }
  39. }
  40. /* 17.1.93 */
  41.  
  42.  
  43.  
  44. typedef struct {
  45.     unsigned version;
  46.     unsigned headlen;
  47.     unsigned nplanes;
  48.     unsigned patlen;
  49.     unsigned pixelw;
  50.     unsigned pixelh;
  51.     unsigned linew;
  52.     unsigned lines;
  53. /*    unsigned palette[16]; Sind eh monochrom */
  54. } IMGHEADER;
  55.  
  56.  
  57. char    tmp_zeile[8192];    /* Gedrehte Zeilen + Sicherheit */
  58. char    line[8192];    /* Gedrehte Zeilen + Sicherheit */
  59. char    display_status[4]="\033H*";
  60. extern char    tmp_file[256]; /* In Datei drucken? */
  61.  
  62.  
  63. /* Datei ausdrucken */
  64. WORD    drucke( UBYTE *p, LONG weite, LONG hoehe, LONG h_dpi, LONG v_dpi )
  65. {
  66.     IMGHEADER    hdr;
  67.     LONG            max_spalte, wweite, lz;
  68.     WORD            th, work_in[12], work[56];
  69.     LONG            rep, x, i;
  70.  
  71.     if(  vq_gdos()==0  )
  72.     {
  73.         Cconout( 7 );
  74.         return -1;
  75.     }
  76.     th = (WORD)get_tempfile( "img" );
  77.     if(  th<0  )
  78.         return -1;
  79.  
  80.         /* Header */
  81.     hdr.version = 1;
  82.     hdr.headlen = (WORD)sizeof(IMGHEADER)/2;
  83.     hdr.nplanes = 1;
  84.     hdr.patlen = 2;
  85.         /* Grafikauflösung festlegen */
  86.     hdr.pixelw = (WORD)((25400L+v_dpi/2)/v_dpi);
  87.     hdr.pixelh = (WORD)((25400L+h_dpi/2)/h_dpi);
  88.         /* Grafikweite festlegen */
  89.     hdr.linew = (WORD)hoehe;
  90.     hdr.lines = (WORD)weite;
  91.     Fwrite( th, sizeof(IMGHEADER), &hdr );
  92.  
  93.     max_spalte = (hoehe+7)/8;
  94.     x = 0;
  95.     wweite = (weite+15)/16;
  96.     wweite *= 2;
  97.     Cconws( display_status );
  98.  
  99.     for(  i=0;  x<weite;  x++  )
  100.     {
  101.         if(  (x%128)==0  )
  102.         {
  103.             Cconws( display_status );
  104.             display_status[2] ^= 1;
  105.         }
  106.         drehe_90( p, tmp_zeile, wweite, max_spalte, x );
  107.          Fwrite( th, 4L, "\000\000\377\001" );
  108.  
  109.             /* Eine Zeile in die Datei! */
  110.         rep = lz = max_spalte;
  111.         i = 0;
  112.         while(  lz>0  )
  113.             i += compress_img_run( line+i, tmp_zeile+rep-lz, &lz );
  114.         Fwrite( th, (LONG)i, line );
  115.      }
  116.      Fclose( th );
  117.  
  118.     /* Und nun die Ausgabe auf Gerät 21 */
  119.   for(  i=1;  i<10;  i++  )
  120.     work_in[i] = 1;
  121.   work_in[10] = 2; /* Raster-Koordinaten! */
  122.   work_in[0] = th = 21;
  123.     v_opnwk( work_in, &th, work );
  124.     if(  th>0  )
  125.     {
  126.         Cconws( "\033Hp" );
  127.         work_in[0] = work_in[1] = 0;
  128.         work_in[2] = work[0];
  129.         work_in[3] = work[1];
  130.         v_bit_image(    th, tmp_file, 0,
  131.                                     1, 1, /* Ganzahlig xy */
  132.                                     0, 0, /* Links oben */
  133.                                     work_in );
  134.         v_updwk( th );
  135.         v_clswk( th );
  136.         Fdelete( tmp_file );
  137.     }
  138.     else
  139.         Cconout( 7 );
  140.  
  141.     return 0;
  142. }
  143.  
  144.  
  145.